#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct cake {
	ll x,y,z;
} a[11010];
inline long long read(){
	long long x;
	scanf("%lld",&x);
	return x;
}
cake struct_read(){
	cake tmp;
	tmp.x=read(),tmp.y=read(),tmp.z=read();
	return tmp;
}
ll b[11010],ans=0;
inline long long read_INT(){
    int x;
    scanf("%d",&x);
    return x;
}
int main() {
	int n=read_INT(),m=read_INT();
	for(int i=1; i<=n; i++)a[i]=struct_read();//scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].z);
	for(int p=-1; p<=1; p+=2){
		for(int k=-1; k<=1; k+=2){
			for(int i=-1; i<=1; i+=2) {
				for(int j=1; j<=n; j++)b[j]=p*a[j].x+k*a[j].y+i*a[j].z;
				sort(b+1,b+1+n);
				ll sum=0;
				for(int j=n; j>=n-m+1; j--)sum+=b[j];
				ans=max(ans,sum);
			}
        }
    }
	printf("%lld",ans);
	return 0;
}